import Vue from 'vue'
import store from '../@base/initStore.js'
Vue.directive('Dist', (el, binding, vnode) => {
    var options = binding.value;
    if (options[0] && options[1]) {
        store.dispatch('Dist/formatCommonDistByKey', {
            type: options[0],
            key: options[2] || 'DM',
        }).then(res => {
            var valueKey = options[3] || 'MC';
            try {
                var _value = res[options[1]][valueKey];
                el.innerHTML = _value;
            } catch (error) {
                console.error('未查找到对应字典项值，请检查参数 : ', options, error);
            }
        }).catch(error => {
            console.error('字典项加载失败，请检查参数 : ', options, error);
        });
    } else {
        console.error('无法加载字典项，请检查参数配置 : ', options);
    }
})

